package apps.generate.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;

import apps.generate.domain.DBFieldBean;

@Component
public class DBFieldDAO extends JdbcDaoSupport<DBFieldBean>{

	public List<DBFieldBean> getFieldListOfTableName(String tableName) {
		String sql="SELECT COL.COLUMN_NAME, COM.COMMENTS, COL.DATA_TYPE FROM USER_TAB_COLUMNS COL " +
				"INNER JOIN USER_COL_COMMENTS COM " +
				"ON COL.TABLE_NAME = ? AND COL.TABLE_NAME = COM.TABLE_NAME AND COL.COLUMN_NAME = COM.COLUMN_NAME " +
				"ORDER BY COL.COLUMN_ID";		
		Object[] objects={tableName};
		List<DBFieldBean> list=query(sql, objects, new RowMapper() {
			public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
				DBFieldBean dbFieldBean=new DBFieldBean();
				dbFieldBean.setFieldName(rs.getString("COLUMN_NAME"));
				dbFieldBean.setFieldType(rs.getString("DATA_TYPE"));
				dbFieldBean.setRemark(rs.getString("COMMENTS"));
				return dbFieldBean;
			}
		});
		return list;
	}
	
	
}
